package com.apps.ftapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.apps.ftapp.R;
import com.apps.ftapp.util.L;
import com.apps.ftapp.util.Tools;

import java.util.List;
import java.util.Map;

/**
 * Created by lyli on 2017/10/12.
 */

public class SucModelAdapter extends BaseAdapter {


    String[] typeKey = {"single_choice", "choice", "uncertain_choice", "fill", "determine", "essay", "material"};
    private Context mContext;
    private List<Map> titles;
    private String keys;

    public SucModelAdapter(Context mContext, List<Map> dataList, String keys) {
        super();
        this.mContext = mContext;
        this.titles = dataList;
        this.keys = keys;
    }

    @Override
    public int getCount() {
        if (null == titles) {
            return 0;
        } else {
            return this.titles.size();
        }
    }

    @Override
    public Object getItem(int i) {
        if (titles == null) {
            return null;
        } else {
            return this.titles.get(i);
        }
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        Map tit = titles.get(i);
        ViewHolder holder = null;
        if (view == null) {
            view = LayoutInflater.from(this.mContext).inflate(R.layout.suc_gridview_item, null, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        //判断是否答题

        //


        L.i("main", "" + tit.get("keys"));
        if (Tools.getisYes(Tools.isIntNull(tit.get("type")))) {
            L.i("main", "此韪不。。。。。。。。。需要做的韪");
        } else {
            L.i("main", "需要做的韪");
            boolean isf = Tools.isBooleanNull(tit.get("is"));
            if (isf) {
                holder.textView.setBackgroundResource(R.drawable.yyyy2);
            } else {
                holder.textView.setBackgroundResource(R.drawable.yyy1);
            }

        }


        holder.textView.setText(Tools.isNull(tit.get("index")) + "");
        return view;
    }


    private class ViewHolder {
        TextView textView;

        public ViewHolder(View view) {
            textView = view.findViewById(R.id.biao);
        }
    }

}
